<?php
/*
 * Copyright 2013 by Jerrick Hoang, Ivy Xing, Sam Roberts, James Cook, 
 * Johnny Coster, Judy Yang, Jackson Moniaga, Oliver Radwan, 
 * Maxwell Palmer, Nolan McNair, Taylor Talmage, and Allen Tucker. 
 * This program is part of RMH Homebase, which is free software.  It comes with 
 * absolutely no warranty. You can redistribute and/or modify it under the terms 
 * of the GNU General Public License as published by the Free Software Foundation
 * (see <http://www.gnu.org/licenses/ for more information).
 * 
 */

	session_start();
	session_cache_expire(30);
?>
<!-- page generated by the BowdoinRMH software package -->
<html>
	<head>
		<title>
			Edit Shift
		</title>
		<link rel="stylesheet" href="styles.css" type="text/css" />
	</head>
	<body>
		<div id="container">
			<?PHP include('header.php');?>
			<div id="content">
				<?php
					$shiftid=$_GET['shift'];
					$venue = $_GET['venue'];
					include_once('editShift.inc');
					if($shiftid=="") {
						echo "<p>No Shift ID Supplied.  Click on \"Calendar\" above to edit shifts.</p>";
					}
					else {
						$shift=select_dbShifts($shiftid);
						if(!$shift instanceof Shift)
							echo "<p>Invalid Shift ID Supplied.  Click on \"Calendar\" above to edit shifts.</p>";
						else {
							if(!process_fill_vacancy($_POST,$shift,$venue) &&
							   !process_add_volunteer($_POST,$shift,$venue) &&
							   !process_move_shift($_POST, $shift) &&
							   !process_change_times($_POST, $shift)){
								if (process_unfill_shift($_POST,$shift,$venue))
									$shift=select_dbShifts($shiftid);
								else if (process_add_slot($_POST,$shift,$venue))
									$shift=select_dbShifts($shiftid);
								else if (process_clear_shift($_POST,$shift,$venue))
								    $shift = select_dbShifts($shiftid);
								else if (process_ignore_slot($_POST,$shift,$venue))
									$shift=select_dbShifts($shiftid);
								$persons=$shift->get_persons();
								echo "<br><br><table align=\"center\" border=\"1px\"><tr><td align=\"center\" colspan=\"2\"><b>"
									.get_shift_name_from_id($shiftid)."</b></td></tr>";
								if($_SESSION['access_level']>=2) {
									echo "<tr><td valign=\"top\"><br>&nbsp;".do_slot_num($persons, $shift->num_vacancies())."</td><td>";
								
										echo ("<form method=\"POST\" style=\"margin-bottom:0;\">
											<input type=\"hidden\" name=\"_submit_add_slot\" value=\"1\"><br>
											<input type=\"submit\" value=\"Add Slot\" style=\"width: 150px\"
											name=\"submit\" >
											</form>");
										echo ("<form method=\"POST\" style=\"margin-bottom:0;\">
											<input type=\"hidden\" name=\"_submit_clear_shift\" value=\"1\">
											<input type=\"submit\" value=\"Clear Entire Shift\" style=\"width: 150px\"
											name=\"submit\" >
											</form>");
										echo ("<form method=\"POST\" style=\"margin-bottom:0;\">
											<input type=\"hidden\" name=\"_submit_move_shift\" value=\"1\">
											<input type=\"submit\" value=\"Move Shift\" style=\"width: 150px\"
											name=\"submit\" >
											</form>");
									echo "<br></td></tr>";
								}
								if($shift->num_vacancies()>0) {
									echo("<tr><td valign=\"top\"><br>&nbsp;Find Volunteers<br>&nbsp;To Fill Vacancies</td><td>
										<form method=\"POST\" action=\"subCallList.php?shift=".$shiftid."\" style=\"margin-bottom:0;\">
										<input type=\"hidden\" name=\"_shiftid\" value=\"".$shiftid."\">");
									if(!$shift->has_sub_call_list() && !(select_dbSCL($shift->get_id()) instanceof SCL)) {
										echo "<input type=\"hidden\" name=\"_submit_generate_scl\" value=\"1\"><br>
										<input type=\"submit\" value=\"Generate Sub Call List\" name=\"submit\"
											style=\"width: 150px\">";
									}
									else {
										echo "<input type=\"hidden\" name=\"_submit_view_scl\" value=\"1\"><br>
										<input type=\"submit\" value=\"View Sub Call List\" name=\"submit\" style=\"width: 150px\">";
									}
									echo "</form><br></td></tr>";
								}
							    echo display_filled_slots($persons);
								echo display_vacant_slots($shift->num_vacancies());
								echo "</td></tr></table>";
								echo "<p align=\"center\"><a href=\"calendar.php?id=".substr($shiftid,0,8)."&edit=true&venue=house"."\">
									Back to Calendar</a>";
							}
						}
					}
				?>
				
			</div>
			<?PHP include('footer.inc');?>
		</div>
	</body>
</html>